﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SimpleWPFWindows
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class CheckPasswordWindow : Window
    {
        string checkPassword = null;
        bool isErrorReturn = false;
        private CheckPasswordWindow()
        {
            InitializeComponent();
        }
        public static bool? Show(string message, string checkPassword, bool isErrorReturn = false)
        {
            CheckPasswordWindow win = new CheckPasswordWindow();
            win.textBlockMessage.Text = message;
            win.checkPassword = checkPassword;
            win.isErrorReturn = isErrorReturn;
            return win.ShowDialog();
        }

        private void buttonConfirm_Click(object sender, RoutedEventArgs e)
        {
            if (this.textBoxResult.Password.Equals(this.checkPassword, StringComparison.CurrentCultureIgnoreCase))
            {
                this.DialogResult = true;
                this.Close();
            }
            else if(isErrorReturn)
            {
                this.DialogResult = false;
                this.Close();
            }
        }

        private void buttonCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //this.DialogResult = false;
        }
    }
}
